
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NEW FANGLED STYLE CUT 'N PASTE FUNCTIONS
;; (and other nice keyboard fixes)
;;
;; Defining the Region:
;;
;; . Shift + Cursor movement allows you to define a region
;; . Cursor movement (without Shift) clears the mark (unhighlights the region)
;; . Mouse down 1 + drag allows you to define the region (as in standard emacs)
;; . Mouse down 1 (dbl click) selects the current word (as in standard emacs)
;; * Mouse down 1 (trpl click) doesn't work well with this simplistic package.
;;   The problem is that it will copy the dbl click result into the temp
;;   variable which stores the old x selection; thus if you then insert into
;;   the region (i.e. with Shift+Insert, or mouse2) you would just replace the
;;   whole line with the word you dbl clicked on...
;;   You can still use this function, you just can't use it to define a region
;;   to insert over.
;; . Mouse 3 sets the mark as usual
;; 
;;  
;; Once the region is defined:
;;
;; . If you defined the region with the mouse, then the old x selection is
;;   kept in a temp variable; if you hit mouse down 2, then the temp variable
;;   will replace the region you defined.
;;   So, you can select one word with the mouse, then select another word,
;;   press butn 2 and the first word will replace the second!
;; . Ctrl + Delete deletes the region
;; . Delete copies the region into the kill ring
;; . Typing any other key (i.e. a self-insert-command key) will delete the 
;;   region, then insert themselves, thus in effect replacing the region with
;;   the char you typed.
;; 
;; General Cursor Movement Changes:
;;
;; . Home = beginning of line
;; . Ctrl + Home = beginning of buffer
;; . End, Ctrl + End are similar
;; . Pageup/Pagedown are slightly changed: in default emacs if you try to page
;;   at either end of the buffer you will get an End of buffer message; this
;;   is changed so that the point is actually moved to the beginning/end of 
;;   the buffer.
;; . All of the above understand the "Shift +" idea to extend the mark,
;;   i.e. Ctrl + Shift + End sets the mark at the end of the buffer.
;;
;; Steve Dodd
;; March 1998
;; modified by jzhang @ 18:42:53 2004-02-15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;
;; Use this as a shell around self-insert-command; this function checks if a
;; region is currently defined -- if it is, the region is replaced with the
;; key you pressed to invoke the function.
;; 

(defun s-self-insert-command ()
  (interactive)
  (if mark-active (kill-region (point) (mark)) ())
  (self-insert-command 1))

;;
;; Simple cursor movement functions
;;

(defun s-shift-forward-char ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (forward-char))
(defun s-forward-char ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (forward-char))

(defun s-shift-backward-char ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (backward-char))
(defun s-backward-char ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (backward-char))

(defun s-shift-previous-line1 ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (previous-line 1))
(defun s-previous-line1 ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (previous-line 1))

(defun s-shift-next-line1 ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (next-line 1))
(defun s-next-line1 ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (next-line 1))

;;
;; End, and Home functions
;;

(defun s-shift-end-of-line ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (end-of-line))
(defun s-shift-ctrl-end-of-buffer ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) (message "hi"))
  (goto-char (point-max)))
(defun s-end-of-line ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (end-of-line))

(defun s-shift-beginning-of-line ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (beginning-of-line))
(defun s-shift-ctrl-beginning-of-buffer ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (goto-char (point-min)))
(defun s-beginning-of-line ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (beginning-of-line))

;;
;; Pageup/Pagedown functions
;;

(defun s-shift-scroll-up ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (if (condition-case nil
      (scroll-up)
      (error 't)) (goto-char (point-max)) ()))
(defun s-scroll-up ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (if (condition-case nil
      (scroll-up)
      (error 't)) (goto-char (point-max)) ()))

(defun s-shift-scroll-down ()
  (interactive)
  (if (not mark-active) (set-mark-command nil) ())
  (if (condition-case nil
      (scroll-down)
      (error 't)) (goto-char (point-min)) ()))
(defun s-scroll-down ()
  (interactive)
  (if mark-active (set-mark nil) ())
  (if (condition-case nil
      (scroll-down)
      (error 't)) (goto-char (point-min)) ()))

;;
;; Cut and paste functions
;;

(defun s-kill-delete ()
  (interactive)
  (if mark-active
      (kill-region (point) (mark))
    (delete-char 1))
  (setq s-prev-selection nil))


; This is where we store the old X cutbuffer contents in case the user doesn't
; want the highlighted region on the cutbuffer.
(setq s-prev-selection nil)


;; (substitute-key-definition 'self-insert-command 's-self-insert-command
;; 			   global-map)
;; (define-key global-map [S-right] 's-shift-forward-char)
;; (define-key global-map [right] 's-forward-char)
;; (define-key global-map [S-left] 's-shift-backward-char)
;; (define-key global-map [up] 's-backward-char)
;; (define-key global-map [S-up] 's-shift-previous-line1)
;; (define-key global-map [up] 's-previous-line1)
;; (define-key global-map [S-down] 's-shift-next-line1)
;; (define-key global-map [down] 's-next-line1)
;; (define-key global-map [end] 's-end-of-line)
;; (define-key global-map [S-end] 's-shift-end-of-line)
;; (define-key global-map [C-end] 'end-of-buffer)
;; (define-key global-map [C-S-end] 's-shift-ctrl-end-of-buffer)
;; (define-key global-map [home] 's-beginning-of-line)
;; (define-key global-map [S-home] 's-shift-beginning-of-line)
;; (define-key global-map [C-home] 'beginning-of-buffer)
;; (define-key global-map [C-S-home] 's-shift-ctrl-beginning-of-buffer)
;; (define-key global-map [next] 's-scroll-up)
;; (define-key global-map [S-next] 's-shift-scroll-up)
;; (define-key global-map [prior] 's-scroll-down)
;; (define-key global-map [S-prior] 's-shift-scroll-down)
;; (define-key global-map [delete] 's-kill-delete)
;; (define-key global-map [C-delete] 'delete-region)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of Cut 'n Paste Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
